<?php 

include '../db_functions/users.php';
include '../db_functions/database.php';
session_start();
if(isset($_SESSION['id'])){
	$customer_id = $_SESSION['id'];
}
else { echo "error: there is no active session"; }
$connection=Connect();
$customer_info=ReturnInfobyID($_SESSION['id']);

$orders_result=execute_order_query($customer_id);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>User Profile Page </title>
    <link rel="stylesheet" type="text/css" href="../css/customer.css" />

	 <script type="text/javascript">
		function toggle5(showHideDiv, switchImgTag) {
				var ele = document.getElementById(showHideDiv);
				var imageEle = document.getElementById(switchImgTag);
				if(ele.style.display == "block") {
						ele.style.display = "none";
				imageEle.innerHTML = '<img src="img/plus.png">';
				}
				else {
						ele.style.display = "block";
						imageEle.innerHTML = '<img src="img/minus.png">';
				}
		}	
     </script>
</head>

<body>
	<header id="banner">
		<?php 
			echo "<h3 id=\"uid\">Καλωσορίσατε "; 
			echo $_SESSION['name']." ".$_SESSION['sname']." ! <br/>"; 
			echo '<a href="../index.php">Επιστροφή στη Αρχική Σελίδα</a>';
		?>
    </header>
     
    <div id="info">
        <h2>Προφίλ Χρήστη</h2>
        <form action="" method="post">
            <table style="margin-left: auto;margin-right: auto;"  align="center">
                <tr><td>Όνομα</td><td><input type="text" name="user_name" id="user_name"  VALUE="<?php echo $customer_info['customer_name']?>" size=70></td></tr>
                <tr><td>Επώνυμο</td><td><input type="text" name="user_surname" id="user_surname"  VALUE="<?php echo $customer_info['customer_surname']?>"  size=70></td></tr>
                <tr><td>Διεύθυνση</td><td><input type="text" name="user_address" id="user_address" VALUE="<?php echo $customer_info['customer_address']?>"  size=70></td></tr>
                <tr><td>Όροφος</td><td><input type="text" name="user_floor" id="user_floor" VALUE="<?php echo $customer_info['customer_floor']?>"  size=70></td></tr
                ><tr><td>Τηλέφωνο</td><td><input type="text" name="user_phone" id="user_phone" VALUE="<?php echo $customer_info['customer_phone']?>"  size=70></td></tr>
                <tr><td>Username</td><td><input type="text" name="user_username" id="user_username" VALUE="<?php echo $customer_info['customer_username']?>" disabled="disabled"  size=70></td></tr>
                <tr><td>Password</td><td><input type="text" name="user_password" id="user_password" VALUE="<?php echo $customer_info['customer_password']?>"  size=70></td></tr>
            </table>
            <?php if (empty($customer_info)) echo "There is no info for this username";?>
            <input type="submit" value="Αποθήκευση Αλλαγών">
            
        </form>
    </div>

    <div id="orders">
        <h2>Previous Orders</h2>
        <table>
            <tr><td>Date & Time</td></tr>
            <?php	
                $i="1";
                settype($i, "string");
                $img_id="OrderImg";
                $order_id="Order";
                while($orders_result){ 
			?>
                <tr><td> 
                <a id="<?php echo $img_id.$i ?>" href="javascript:toggle5('<?php echo $order_id.$i ?>', '<?php echo $img_id.$i ?>');"><img src="img/plus.png"></a>
                <?php echo $customer_order['order_datetime']; ?>
                </td></tr>
                <tr><td><DIV id="<?php echo $order_id.$i ?>" style="display: none;">
            		<table border="1" style="border: solid black; " class="orders" cellpadding="5">
                       <tr><td> Date & Time<td>Total<td>Status</tr>
                        <tr>
                        <td style="table-layout:fixed; width:150px;"><?php echo $customer_order['order_datetime']; ?>
                        <td style="table-layout:fixed; width:50px;"><?php echo $customer_order['order_total']; ?>
                        <td style="table-layout:fixed; width:80px;"><?php echo $customer_order['order_status']; ?>
                        </tr>
                    </table>
   				 </div></tr>
			<?php 
				settype($i, "integer");
				$i=$i+1;
				settype($i, "string"); } 
			?>
		</table>
	</div>

<?php mysql_close($connection);//kleinei tin sindesi me tin vasi ?>
</bosy>
</html>